/**
 * Copyright (C) 2008 Christopher Allen Ogden
 *
 *     This file is part of Odysi.
 *
 *  Odysi is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Odysi is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Odysi.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <vector>
#include <map>
#include <string>
#include "std.h"
#include "tile.h"
#include "singleton.h"

class TileManager:public Singleton<TileManager>
{
    public:
        /**
         * Load a set of tiles.
         *
         * @param key       The key to the set of files.
         * @param fileName  The name of the file to load.
         */
        void load(unsigned int key, const std::string &fileName);

        /**
         * Draw a tile.
         *
         * @param key   The key of the set of tiles the tile is in.
         * @param id    The ID of the tile to draw.
         * @param frame The frame to draw.
         * @param x     The X location to draw to.
         * @param y     The Y location to draw to.
         */
        void drawTile(unsigned int key, unsigned int id, unsigned int frame, int x, int y);

        /**
         * Get a tile.
         *
         * @param key   The key of the set of tiles the tile is in.
         * @param id    The ID of the tile.
         * @return      A pointer to the tile.
         */
        Tile *getTile(unsigned int key, unsigned int id);

        /**
         * Clear all the tiles.
         *
         * @param key   The key of the set of tiles to clear.
         */
        void clear(unsigned int key)
        {
            _tile[key].clear();
        }

        /**
         * Get the number of tiles in a set.
         *
         * @param key   The key of the tile set.
         * @return      The number of tiles in the set.
         */
        unsigned int getNumTiles(unsigned int key)
        {
            return _tile[key].size();
        }

    private:
        typedef std::vector<Tile> TileList;
        typedef std::map<unsigned int, TileList> TileListMap;
        TileListMap _tile;
};

